'use strict';
const {verifyToken} =require("wx-common") 

exports.main = async (event, context) => {
	console.log('event',event)
	const db = uniCloud.database();
	const dbCmd = db.command;
	//event为客户端上传的参数
	const {nickName,avatarUrl,gender,country,province,city,token}=event
	const payload =verifyToken(token)
	
	const dbRes= await db.collection('user').where({
		openid:dbCmd.eq(payload.openid) 
	}).update({
		nickName:nickName,
		avatarUrl:avatarUrl,
		gender:gender,
		country:country,
		province:province,
		city:city
	})
	//返回数据给客户端
	return dbRes
};
